/*******************************************************************************
 * Copyright (c) 2008 Nels E. Beckman.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Nels E. Beckman - initial API and implementation
 *******************************************************************************/
package edu.cmu.cs.nbeckman.wptranslator;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.junit.Test;

import antlr.RecognitionException;
import antlr.TokenStreamException;
import edu.cmu.cs.nbeckman.wptranslator.BoldedElement;
import edu.cmu.cs.nbeckman.wptranslator.CenteredElement;
import edu.cmu.cs.nbeckman.wptranslator.Document;
import edu.cmu.cs.nbeckman.wptranslator.Element;
import edu.cmu.cs.nbeckman.wptranslator.ElementList;
import edu.cmu.cs.nbeckman.wptranslator.Text;


/**
 * Run the translator on the files in /test-files.
 * 
 * @author Nels E. Beckma
 */
public class TestFileTest {
	
	@Test
	public void testBOLDTEXT() throws RecognitionException, TokenStreamException, IOException {
		Document doc = Document.createDocumentFromFile(new File("test-files/BOLDTEXT"));
		assertTrue(((ElementList)doc.getElement()).getElements().get(1) instanceof BoldedElement);
	}
	
	@Test
	public void testBRET() throws RecognitionException, TokenStreamException, IOException {
		Document doc = Document.createDocumentFromFile(new File("test-files/BRET"));
		List<Element> elements = ((ElementList)doc.getElement()).getElements();
		assertTrue(elements.get(1) instanceof BoldedElement);
		assertTrue(((BoldedElement)elements.get(1)).getElement() instanceof ElementList);
	}
	
	@Test
	public void testCENTERTX() throws RecognitionException, TokenStreamException, IOException {
		Document doc = Document.createDocumentFromFile(new File("test-files/CENTERTX"));
		assertTrue(((ElementList)doc.getElement()).getElements().get(3) instanceof CenteredElement);
	}
	
	@Test
	public void testTEXTONLY() throws RecognitionException, TokenStreamException, IOException {
		Document doc = Document.createDocumentFromFile(new File("test-files/TEXTONLY"));
		assertTrue(((ElementList)doc.getElement()).getElements().get(0) instanceof Text);
	}
	
	@Test
	public void testULINE() throws RecognitionException, TokenStreamException, IOException {
		Document doc = Document.createDocumentFromFile(new File("test-files/ULINE"));
		assertTrue(((ElementList)doc.getElement()).getElements().get(1) instanceof UnderlinedElement);
	}
	
	@Test
	public void testID3() throws RecognitionException, TokenStreamException, IOException {
		Document doc = Document.createDocumentFromFile(new File("test-files/ID3"));
		assertTrue(((ElementList)doc.getElement()).getElements().get(3) instanceof Indent);
	}
}